//
// DotNetNuke - http://www.dotnetnuke.com
// Copyright (c) 2002-2010
// by Perpetual Motion Interactive Systems Inc. ( http://www.perpetualmotion.ca )
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions 
// of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE.
//

using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using DotNetNuke.Common.Lists;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Security.Permissions;
namespace DotNetNuke.UI.UserControls
{
	public abstract class Address : Framework.UserControlBase
	{
		protected System.Web.UI.HtmlControls.HtmlTableRow rowStreet;
		protected UI.UserControls.LabelControl plStreet;
		protected System.Web.UI.WebControls.TextBox txtStreet;
		protected System.Web.UI.WebControls.CheckBox chkStreet;
		protected System.Web.UI.WebControls.Label lblStreetRequired;
		protected System.Web.UI.WebControls.RequiredFieldValidator valStreet;
		protected System.Web.UI.HtmlControls.HtmlTableRow rowUnit;
		protected UI.UserControls.LabelControl plUnit;
		protected System.Web.UI.WebControls.TextBox txtUnit;
		protected System.Web.UI.HtmlControls.HtmlTableRow rowCity;
		protected UI.UserControls.LabelControl plCity;
		protected System.Web.UI.WebControls.TextBox txtCity;
		protected System.Web.UI.WebControls.CheckBox chkCity;
		protected System.Web.UI.WebControls.Label lblCityRequired;
		protected System.Web.UI.WebControls.RequiredFieldValidator valCity;
		protected System.Web.UI.HtmlControls.HtmlTableRow rowCountry;
		protected UI.UserControls.LabelControl plCountry;
		protected DotNetNuke.UI.WebControls.CountryListBox cboCountry;
		protected System.Web.UI.WebControls.CheckBox chkCountry;
		protected System.Web.UI.WebControls.Label lblCountryRequired;
		protected System.Web.UI.WebControls.RequiredFieldValidator valCountry;
		protected System.Web.UI.HtmlControls.HtmlTableRow rowRegion;
		protected UI.UserControls.LabelControl plRegion;
		protected System.Web.UI.WebControls.Label lblRegion;
		protected System.Web.UI.WebControls.DropDownList cboRegion;
		protected System.Web.UI.WebControls.TextBox txtRegion;
		protected System.Web.UI.WebControls.CheckBox chkRegion;
		protected System.Web.UI.WebControls.Label lblRegionRequired;
		protected System.Web.UI.WebControls.RequiredFieldValidator valRegion1;
		protected System.Web.UI.WebControls.RequiredFieldValidator valRegion2;
		protected System.Web.UI.HtmlControls.HtmlTableRow rowPostal;
		protected UI.UserControls.LabelControl plPostal;
		protected System.Web.UI.WebControls.TextBox txtPostal;
		protected System.Web.UI.WebControls.CheckBox chkPostal;
		protected System.Web.UI.WebControls.Label lblPostalRequired;
		protected System.Web.UI.WebControls.RequiredFieldValidator valPostal;
		protected System.Web.UI.HtmlControls.HtmlTableRow rowTelephone;
		protected UI.UserControls.LabelControl plTelephone;
		protected System.Web.UI.WebControls.TextBox txtTelephone;
		protected System.Web.UI.WebControls.CheckBox chkTelephone;
		protected System.Web.UI.WebControls.Label lblTelephoneRequired;
		protected System.Web.UI.WebControls.RequiredFieldValidator valTelephone;
		protected System.Web.UI.HtmlControls.HtmlTableRow rowCell;
		protected UI.UserControls.LabelControl plCell;
		protected System.Web.UI.WebControls.TextBox txtCell;
		protected System.Web.UI.WebControls.CheckBox chkCell;
		protected System.Web.UI.WebControls.Label lblCellRequired;
		protected System.Web.UI.WebControls.RequiredFieldValidator valCell;
		protected System.Web.UI.HtmlControls.HtmlTableRow rowFax;
		protected UI.UserControls.LabelControl plFax;
		protected System.Web.UI.WebControls.TextBox txtFax;
		protected System.Web.UI.WebControls.CheckBox chkFax;
		protected System.Web.UI.WebControls.Label lblFaxRequired;
		protected System.Web.UI.WebControls.RequiredFieldValidator valFax;
		private int _ModuleId;
		private string _LabelColumnWidth = "";
		private string _ControlColumnWidth = "";
		private int _StartTabIndex = 1;
		private string _Street;
		private string _Unit;
		private string _City;
		private string _Country;
		private string _Region;
		private string _Postal;
		private string _Telephone;
		private string _Cell;
		private string _Fax;
		private bool _ShowStreet = true;
		private bool _ShowUnit = true;
		private bool _ShowCity = true;
		private bool _ShowCountry = true;
		private bool _ShowRegion = true;
		private bool _ShowPostal = true;
		private bool _ShowTelephone = true;
		private bool _ShowCell = true;
		private bool _ShowFax = true;
		private string _CountryData = "Text";
		private string _RegionData = "Text";
		private string MyFileName = "Address.ascx";
		public int ModuleId
		{
			get { return Convert.ToInt32(ViewState["ModuleId"]); }
			set { _ModuleId = value; }
		}
		public string LabelColumnWidth
		{
			get { return Convert.ToString(ViewState["LabelColumnWidth"]); }
			set { _LabelColumnWidth = value; }
		}
		public string ControlColumnWidth
		{
			get { return Convert.ToString(ViewState["ControlColumnWidth"]); }
			set { _ControlColumnWidth = value; }
		}
		public int StartTabIndex
		{
			set { _StartTabIndex = value; }
		}
		public string Street
		{
			get { return txtStreet.Text; }
			set { _Street = value; }
		}
		public string Unit
		{
			get { return txtUnit.Text; }
			set { _Unit = value; }
		}
		public string City
		{
			get { return txtCity.Text; }
			set { _City = value; }
		}
		public string Country
		{
			get
			{
				string retValue = "";
				if (cboCountry.SelectedItem != null)
				{
					switch (_CountryData.ToLower())
					{
						case "text":
							if (cboCountry.SelectedIndex == 0)
							{
								retValue = "";
							}
							else
							{
								retValue = cboCountry.SelectedItem.Text;
							}
							break;
						case "value":
							retValue = cboCountry.SelectedItem.Value;
							break;
					}
				}
				return retValue;
			}
			set { _Country = value; }
		}
		public string Region
		{
			get
			{
				string retValue = "";
				if (cboRegion.Visible)
				{
					if (cboRegion.SelectedItem != null)
					{
						switch (_RegionData.ToLower())
						{
							case "text":
								if (cboRegion.SelectedIndex > 0)
								{
									retValue = cboRegion.SelectedItem.Text;
								}
								break;
							case "value":
								retValue = cboRegion.SelectedItem.Value;
								break;
						}
					}
				}
				else
				{
					retValue = txtRegion.Text;
				}
				return retValue;
			}
			set { _Region = value; }
		}
		public string Postal
		{
			get { return txtPostal.Text; }
			set { _Postal = value; }
		}
		public string Telephone
		{
			get { return txtTelephone.Text; }
			set { _Telephone = value; }
		}
		public string Cell
		{
			get { return txtCell.Text; }
			set { _Cell = value; }
		}
		public string Fax
		{
			get { return txtFax.Text; }
			set { _Fax = value; }
		}
		public bool ShowStreet
		{
			set { _ShowStreet = value; }
		}
		public bool ShowUnit
		{
			set { _ShowUnit = value; }
		}
		public bool ShowCity
		{
			set { _ShowCity = value; }
		}
		public bool ShowCountry
		{
			set { _ShowCountry = value; }
		}
		public bool ShowRegion
		{
			set { _ShowRegion = value; }
		}
		public bool ShowPostal
		{
			set { _ShowPostal = value; }
		}
		public bool ShowTelephone
		{
			set { _ShowTelephone = value; }
		}
		public bool ShowCell
		{
			set { _ShowCell = value; }
		}
		public bool ShowFax
		{
			set { _ShowFax = value; }
		}
		public string CountryData
		{
			set { _CountryData = value; }
		}
		public string RegionData
		{
			set { _RegionData = value; }
		}
		public string LocalResourceFile
		{
			get { return Services.Localization.Localization.GetResourceFile(this, MyFileName); }
		}
		private void Localize()
		{
			string countryCode = cboCountry.SelectedItem.Value;
			ListController ctlEntry = new ListController();
			string listKey = "Country." + countryCode;
			ListEntryInfoCollection entryCollection = ctlEntry.GetListEntryInfoCollection("Region", listKey);
			if (entryCollection.Count != 0)
			{
				cboRegion.Visible = true;
				txtRegion.Visible = false;
				{
					cboRegion.Items.Clear();
					cboRegion.DataSource = entryCollection;
					cboRegion.DataBind();
					cboRegion.Items.Insert(0, new ListItem("<" + Services.Localization.Localization.GetString("Not_Specified", Services.Localization.Localization.SharedResourceFile) + ">", ""));
				}
				if (countryCode.ToLower() == "us")
				{
					valRegion1.Enabled = true;
					valRegion2.Enabled = false;
					valRegion1.ErrorMessage = Services.Localization.Localization.GetString("StateRequired", Services.Localization.Localization.GetResourceFile(this, MyFileName));
					plRegion.Text = Services.Localization.Localization.GetString("plState", Services.Localization.Localization.GetResourceFile(this, MyFileName));
					plRegion.HelpText = Services.Localization.Localization.GetString("plState.Help", Services.Localization.Localization.GetResourceFile(this, MyFileName));
					plPostal.Text = Services.Localization.Localization.GetString("plZip", Services.Localization.Localization.GetResourceFile(this, MyFileName));
					plPostal.HelpText = Services.Localization.Localization.GetString("plZip.Help", Services.Localization.Localization.GetResourceFile(this, MyFileName));
				}
				else
				{
					valRegion1.ErrorMessage = Services.Localization.Localization.GetString("ProvinceRequired", Services.Localization.Localization.GetResourceFile(this, MyFileName));
					plRegion.Text = Services.Localization.Localization.GetString("plProvince", Services.Localization.Localization.GetResourceFile(this, MyFileName));
					plRegion.HelpText = Services.Localization.Localization.GetString("plProvince.Help", Services.Localization.Localization.GetResourceFile(this, MyFileName));
					plPostal.Text = Services.Localization.Localization.GetString("plPostal", Services.Localization.Localization.GetResourceFile(this, MyFileName));
					plPostal.HelpText = Services.Localization.Localization.GetString("plPostal.Help", Services.Localization.Localization.GetResourceFile(this, MyFileName));
				}
				valRegion1.Enabled = true;
				valRegion2.Enabled = false;
			}
			else
			{
				cboRegion.ClearSelection();
				cboRegion.Visible = false;
				txtRegion.Visible = true;
				valRegion1.Enabled = false;
				valRegion2.Enabled = true;
				valRegion2.ErrorMessage = Services.Localization.Localization.GetString("RegionRequired", Services.Localization.Localization.GetResourceFile(this, MyFileName));
				plRegion.Text = Services.Localization.Localization.GetString("plRegion", Services.Localization.Localization.GetResourceFile(this, MyFileName));
				plRegion.HelpText = Services.Localization.Localization.GetString("plRegion.Help", Services.Localization.Localization.GetResourceFile(this, MyFileName));
				plPostal.Text = Services.Localization.Localization.GetString("plPostal", Services.Localization.Localization.GetResourceFile(this, MyFileName));
				plPostal.HelpText = Services.Localization.Localization.GetString("plPostal.Help", Services.Localization.Localization.GetResourceFile(this, MyFileName));
			}
			if (String.IsNullOrEmpty(lblRegionRequired.Text))
			{
				valRegion1.Enabled = false;
				valRegion2.Enabled = false;
			}
		}
		private void ShowRequiredFields()
		{
			Dictionary<string, string> settings = PortalController.GetPortalSettingsDictionary(PortalSettings.PortalId);
			lblStreetRequired.Text = PortalController.GetPortalSettingAsBoolean("addressstreet", PortalSettings.PortalId, true) ? "*" : "";
			lblCityRequired.Text = PortalController.GetPortalSettingAsBoolean("addresscity", PortalSettings.PortalId, true) ? "*" : "";
			lblCountryRequired.Text = PortalController.GetPortalSettingAsBoolean("addresscountry", PortalSettings.PortalId, true) ? "*" : "";
			lblRegionRequired.Text = PortalController.GetPortalSettingAsBoolean("addressregion", PortalSettings.PortalId, true) ? "*" : "";
			lblPostalRequired.Text = PortalController.GetPortalSettingAsBoolean("addresspostal", PortalSettings.PortalId, true) ? "*" : "";
			lblTelephoneRequired.Text = PortalController.GetPortalSettingAsBoolean("addresstelephone", PortalSettings.PortalId, true) ? "*" : "";
			lblCellRequired.Text = PortalController.GetPortalSettingAsBoolean("addresscell", PortalSettings.PortalId, true) ? "*" : "";
			lblFaxRequired.Text = PortalController.GetPortalSettingAsBoolean("addressfax", PortalSettings.PortalId, true) ? "*" : "";
			if (TabPermissionController.CanAdminPage())
			{
				if (lblCountryRequired.Text == "*")
				{
					chkCountry.Checked = true;
					valCountry.Enabled = true;
				}
				if (lblRegionRequired.Text == "*")
				{
					chkRegion.Checked = true;
					if (cboRegion.Visible == true)
					{
						valRegion1.Enabled = true;
						valRegion2.Enabled = false;
					}
					else
					{
						valRegion1.Enabled = false;
						valRegion2.Enabled = true;
					}
				}
				if (lblCityRequired.Text == "*")
				{
					chkCity.Checked = true;
					valCity.Enabled = true;
				}
				if (lblStreetRequired.Text == "*")
				{
					chkStreet.Checked = true;
					valStreet.Enabled = true;
				}
				if (lblPostalRequired.Text == "*")
				{
					chkPostal.Checked = true;
					valPostal.Enabled = true;
				}
				if (lblTelephoneRequired.Text == "*")
				{
					chkTelephone.Checked = true;
					valTelephone.Enabled = true;
				}
				if (lblCellRequired.Text == "*")
				{
					chkCell.Checked = true;
					valCell.Enabled = true;
				}
				if (lblFaxRequired.Text == "*")
				{
					chkFax.Checked = true;
					valFax.Enabled = true;
				}
			}
			if (String.IsNullOrEmpty(lblCountryRequired.Text))
			{
				valCountry.Enabled = false;
			}
			if (String.IsNullOrEmpty(lblRegionRequired.Text))
			{
				valRegion1.Enabled = false;
				valRegion2.Enabled = false;
			}
			if (String.IsNullOrEmpty(lblCityRequired.Text))
			{
				valCity.Enabled = false;
			}
			if (String.IsNullOrEmpty(lblStreetRequired.Text))
			{
				valStreet.Enabled = false;
			}
			if (String.IsNullOrEmpty(lblPostalRequired.Text))
			{
				valPostal.Enabled = false;
			}
			if (String.IsNullOrEmpty(lblTelephoneRequired.Text))
			{
				valTelephone.Enabled = false;
			}
			if (String.IsNullOrEmpty(lblCellRequired.Text))
			{
				valCell.Enabled = false;
			}
			if (String.IsNullOrEmpty(lblFaxRequired.Text))
			{
				valFax.Enabled = false;
			}
		}
		private void UpdateRequiredFields()
		{
			if (chkCountry.Checked == false)
			{
				chkRegion.Checked = false;
			}
			PortalController.UpdatePortalSetting(PortalSettings.PortalId, "addressstreet", chkStreet.Checked ? "" : "N");
			PortalController.UpdatePortalSetting(PortalSettings.PortalId, "addresscity", chkCity.Checked ? "" : "N");
			PortalController.UpdatePortalSetting(PortalSettings.PortalId, "addresscountry", chkCountry.Checked ? "" : "N");
			PortalController.UpdatePortalSetting(PortalSettings.PortalId, "addressregion", chkRegion.Checked ? "" : "N");
			PortalController.UpdatePortalSetting(PortalSettings.PortalId, "addresspostal", chkPostal.Checked ? "" : "N");
			PortalController.UpdatePortalSetting(PortalSettings.PortalId, "addresstelephone", chkTelephone.Checked ? "" : "N");
			PortalController.UpdatePortalSetting(PortalSettings.PortalId, "addresscell", chkCell.Checked ? "" : "N");
			PortalController.UpdatePortalSetting(PortalSettings.PortalId, "addressfax", chkFax.Checked ? "" : "N");
			ShowRequiredFields();
		}
		protected override void OnLoad(EventArgs e)
		{
			base.OnLoad(e);

			cboCountry.SelectedIndexChanged += new EventHandler(cboCountry_SelectedIndexChanged);
			chkCell.CheckedChanged += new EventHandler(chkCell_CheckedChanged);
			chkCity.CheckedChanged += new EventHandler(chkCity_CheckedChanged);
			chkCountry.CheckedChanged += new EventHandler(chkCountry_CheckedChanged);
			chkFax.CheckedChanged += new EventHandler(chkFax_CheckedChanged);
			chkPostal.CheckedChanged += new EventHandler(chkPostal_CheckedChanged);
			chkRegion.CheckedChanged += new EventHandler(chkRegion_CheckedChanged);
			chkStreet.CheckedChanged += new EventHandler(chkStreet_CheckedChanged);
			chkTelephone.CheckedChanged += new EventHandler(chkTelephone_CheckedChanged);

			try
			{
				valStreet.ErrorMessage = Services.Localization.Localization.GetString("StreetRequired", Services.Localization.Localization.GetResourceFile(this, MyFileName));
				valCity.ErrorMessage = Services.Localization.Localization.GetString("CityRequired", Services.Localization.Localization.GetResourceFile(this, MyFileName));
				valCountry.ErrorMessage = Services.Localization.Localization.GetString("CountryRequired", Services.Localization.Localization.GetResourceFile(this, MyFileName));
				valPostal.ErrorMessage = Services.Localization.Localization.GetString("PostalRequired", Services.Localization.Localization.GetResourceFile(this, MyFileName));
				valTelephone.ErrorMessage = Services.Localization.Localization.GetString("TelephoneRequired", Services.Localization.Localization.GetResourceFile(this, MyFileName));
				valCell.ErrorMessage = Services.Localization.Localization.GetString("CellRequired", Services.Localization.Localization.GetResourceFile(this, MyFileName));
				valFax.ErrorMessage = Services.Localization.Localization.GetString("FaxRequired", Services.Localization.Localization.GetResourceFile(this, MyFileName));
				if (!Page.IsPostBack)
				{
					if (!String.IsNullOrEmpty(_LabelColumnWidth))
					{
						plCountry.Width = System.Web.UI.WebControls.Unit.Parse(_LabelColumnWidth);
						plRegion.Width = System.Web.UI.WebControls.Unit.Parse(_LabelColumnWidth);
						plCity.Width = System.Web.UI.WebControls.Unit.Parse(_LabelColumnWidth);
						plStreet.Width = System.Web.UI.WebControls.Unit.Parse(_LabelColumnWidth);
						plUnit.Width = System.Web.UI.WebControls.Unit.Parse(_LabelColumnWidth);
						plPostal.Width = System.Web.UI.WebControls.Unit.Parse(_LabelColumnWidth);
						plTelephone.Width = System.Web.UI.WebControls.Unit.Parse(_LabelColumnWidth);
						plCell.Width = System.Web.UI.WebControls.Unit.Parse(_LabelColumnWidth);
						plFax.Width = System.Web.UI.WebControls.Unit.Parse(_LabelColumnWidth);
					}
					if (!String.IsNullOrEmpty(_ControlColumnWidth))
					{
						cboCountry.Width = System.Web.UI.WebControls.Unit.Parse(_ControlColumnWidth);
						cboRegion.Width = System.Web.UI.WebControls.Unit.Parse(_ControlColumnWidth);
						txtRegion.Width = System.Web.UI.WebControls.Unit.Parse(_ControlColumnWidth);
						txtCity.Width = System.Web.UI.WebControls.Unit.Parse(_ControlColumnWidth);
						txtStreet.Width = System.Web.UI.WebControls.Unit.Parse(_ControlColumnWidth);
						txtUnit.Width = System.Web.UI.WebControls.Unit.Parse(_ControlColumnWidth);
						txtPostal.Width = System.Web.UI.WebControls.Unit.Parse(_ControlColumnWidth);
						txtTelephone.Width = System.Web.UI.WebControls.Unit.Parse(_ControlColumnWidth);
						txtCell.Width = System.Web.UI.WebControls.Unit.Parse(_ControlColumnWidth);
						txtFax.Width = System.Web.UI.WebControls.Unit.Parse(_ControlColumnWidth);
					}
					txtStreet.TabIndex = Convert.ToInt16(_StartTabIndex);
					txtUnit.TabIndex = Convert.ToInt16(_StartTabIndex + 1);
					txtCity.TabIndex = Convert.ToInt16(_StartTabIndex + 2);
					cboCountry.TabIndex = Convert.ToInt16(_StartTabIndex + 3);
					cboRegion.TabIndex = Convert.ToInt16(_StartTabIndex + 4);
					txtRegion.TabIndex = Convert.ToInt16(_StartTabIndex + 5);
					txtPostal.TabIndex = Convert.ToInt16(_StartTabIndex + 6);
					txtTelephone.TabIndex = Convert.ToInt16(_StartTabIndex + 7);
					txtCell.TabIndex = Convert.ToInt16(_StartTabIndex + 8);
					txtFax.TabIndex = Convert.ToInt16(_StartTabIndex + 9);
					ListController ctlEntry = new ListController();
					ListEntryInfoCollection entryCollection = ctlEntry.GetListEntryInfoCollection("Country");
					cboCountry.DataSource = entryCollection;
					cboCountry.DataBind();
					cboCountry.Items.Insert(0, new ListItem("<" + Services.Localization.Localization.GetString("Not_Specified", Services.Localization.Localization.SharedResourceFile) + ">", ""));
					switch (_CountryData.ToLower())
					{
						case "text":
							if (String.IsNullOrEmpty(_Country))
							{
								cboCountry.SelectedIndex = 0;
							}
							else
							{
								if (cboCountry.Items.FindByText(_Country) != null)
								{
									cboCountry.ClearSelection();
									cboCountry.Items.FindByText(_Country).Selected = true;
								}
							}
							break;
						case "value":
							if (cboCountry.Items.FindByValue(_Country) != null)
							{
								cboCountry.ClearSelection();
								cboCountry.Items.FindByValue(_Country).Selected = true;
							}
							break;
					}
					Localize();
					if (cboRegion.Visible)
					{
						switch (_RegionData.ToLower())
						{
							case "text":
								if (String.IsNullOrEmpty(_Region))
								{
									cboRegion.SelectedIndex = 0;
								}
								else
								{
									if (cboRegion.Items.FindByText(_Region) != null)
									{
										cboRegion.Items.FindByText(_Region).Selected = true;
									}
								}
								break;
							case "value":
								if (cboRegion.Items.FindByValue(_Region) != null)
								{
									cboRegion.Items.FindByValue(_Region).Selected = true;
								}
								break;
						}
					}
					else
					{
						txtRegion.Text = _Region;
					}
					txtStreet.Text = _Street;
					txtUnit.Text = _Unit;
					txtCity.Text = _City;
					txtPostal.Text = _Postal;
					txtTelephone.Text = _Telephone;
					txtCell.Text = _Cell;
					txtFax.Text = _Fax;
					rowStreet.Visible = _ShowStreet;
					rowUnit.Visible = _ShowUnit;
					rowCity.Visible = _ShowCity;
					rowCountry.Visible = _ShowCountry;
					rowRegion.Visible = _ShowRegion;
					rowPostal.Visible = _ShowPostal;
					rowTelephone.Visible = _ShowTelephone;
					rowCell.Visible = _ShowCell;
					rowFax.Visible = _ShowFax;
					if (TabPermissionController.CanAdminPage())
					{
						chkStreet.Visible = true;
						chkCity.Visible = true;
						chkCountry.Visible = true;
						chkRegion.Visible = true;
						chkPostal.Visible = true;
						chkTelephone.Visible = true;
						chkCell.Visible = true;
						chkFax.Visible = true;
					}
					ViewState["ModuleId"] = Convert.ToString(_ModuleId);
					ViewState["LabelColumnWidth"] = _LabelColumnWidth;
					ViewState["ControlColumnWidth"] = _ControlColumnWidth;
					ShowRequiredFields();
				}
			}
			catch (Exception exc)
			{
				Services.Exceptions.Exceptions.ProcessModuleLoadException(this, exc);
			}
		}

		protected void cboCountry_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			try
			{
				Localize();
			}
			catch (Exception exc)
			{
				Services.Exceptions.Exceptions.ProcessModuleLoadException(this, exc);
			}
		}
		protected void chkCity_CheckedChanged(object sender, System.EventArgs e)
		{
			try
			{
				UpdateRequiredFields();
			}
			catch (Exception exc)
			{
				Services.Exceptions.Exceptions.ProcessModuleLoadException(this, exc);
			}
		}
		protected void chkCountry_CheckedChanged(object sender, System.EventArgs e)
		{
			try
			{
				UpdateRequiredFields();
			}
			catch (Exception exc)
			{
				Services.Exceptions.Exceptions.ProcessModuleLoadException(this, exc);
			}
		}
		protected void chkPostal_CheckedChanged(object sender, System.EventArgs e)
		{
			try
			{
				UpdateRequiredFields();
			}
			catch (Exception exc)
			{
				Services.Exceptions.Exceptions.ProcessModuleLoadException(this, exc);
			}
		}
		protected void chkRegion_CheckedChanged(object sender, System.EventArgs e)
		{
			try
			{
				UpdateRequiredFields();
			}
			catch (Exception exc)
			{
				Services.Exceptions.Exceptions.ProcessModuleLoadException(this, exc);
			}
		}
		protected void chkStreet_CheckedChanged(object sender, System.EventArgs e)
		{
			try
			{
				UpdateRequiredFields();
			}
			catch (Exception exc)
			{
				Services.Exceptions.Exceptions.ProcessModuleLoadException(this, exc);
			}
		}
		protected void chkTelephone_CheckedChanged(object sender, System.EventArgs e)
		{
			try
			{
				UpdateRequiredFields();
			}
			catch (Exception exc)
			{
				Services.Exceptions.Exceptions.ProcessModuleLoadException(this, exc);
			}
		}
		protected void chkCell_CheckedChanged(object sender, System.EventArgs e)
		{
			try
			{
				UpdateRequiredFields();
			}
			catch (Exception exc)
			{
				Services.Exceptions.Exceptions.ProcessModuleLoadException(this, exc);
			}
		}
		protected void chkFax_CheckedChanged(object sender, System.EventArgs e)
		{
			try
			{
				UpdateRequiredFields();
			}
			catch (Exception exc)
			{
				Services.Exceptions.Exceptions.ProcessModuleLoadException(this, exc);
			}
		}
	}
}
